# 4-12 修改微实践中的程序，将54张牌中的51张随机分发给3位玩家，其中每人17张牌
# poker.py
import random # 导入随机数

from matplotlib.pyplot import ylabel

suits = ["Spades","Hearts","Diamonds","Clubs"] # 四种花色
ranks = ["A","2","3","4","5","6","7","8","9","10","J","Q","K"] # 十三种牌面
# 将花色与牌面组合并加上大小王，生成54张牌的列表
cards = [x+"_"+y for x in suits for y in ranks] + ["Red Joker","Black Joker"]
# 生成三个玩家的持牌列表，和一个存放地主牌的列表
player_1 = []
player_2 = []
player_3 = []
three_cards = []
for i in range(51):        # 循环51次共取51张牌
    idx = random.randint(0,len(cards)-1)  # 生成一个0~剩余牌数-1的随机数
    c = cards.pop(idx)      # 将指定下标的牌取出
    # 随机分给3个玩家
    if len(player_1) < 17:
        player_1.append(c)
    elif len(player_2) < 17:
        player_2.append(c)
    else:
        player_3.append(c)
# 剩下的三张牌当作地主牌
three_cards = cards
# 将三位玩家的持牌列表和地主牌打印出来
print(f"player_1's cards:{player_1}")
print(f"player_2's cards:{player_2}")
print(f"player_3's cards:{player_3}")
print(f"three_cards cards:{three_cards}")
